//
//  MeViewController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/13.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MeViewController.h"
#import "MeHomeHeaderView.h"
#import "MeHomeCell.h"
#import "MeSettingController.h"
#import "UserFeedbackController.h"
#import "MyWalletController.h"
#import "QrCodeCardController.h"
#import "BrowsingHistoryController.h"
#import "MyCommentsController.h"
#import "MyCollectionController.h"
#import "MyMessageController.h"

@interface MeViewController ()<UITableViewDelegate,UITableViewDataSource>
/**listView*/
@property (nonatomic,strong)UITableView*listView;
/**表头*/
@property (nonatomic,strong)MeHomeHeaderView*headerView;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSource;
/**图片数组*/
@property (nonatomic,strong)NSMutableArray*imagesArray;
@end

@implementation MeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"";
    [self.view addSubview:self.listView];
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setNavBarBackgroundAndClearColor];
}
#pragma mark ---<UITableViewDelegate,UITableViewDataSource
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 12.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataSource.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray * array = self.dataSource[section];
    return array.count;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return UIView.new;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return UIView.new;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MeHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(MeHomeCell.class)];
    cell.name = self.dataSource[indexPath.section][indexPath.row];
    cell.leftImageName =self.imagesArray[indexPath.section][indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row ==0) {
        [self.navigationController pushViewController:[MyWalletController new] animated:YES];
    }else if (indexPath.section == 0 && indexPath.row == 1){
        [self.navigationController pushViewController:[BrowsingHistoryController new] animated:YES];
    }else if (indexPath.section == 0 && indexPath.row == 2){
        [self.navigationController pushViewController:[MyMessageController new] animated:YES];
        
    }else if (indexPath.section == 0 && indexPath.row == 3){
        
        [self.navigationController pushViewController:[MyCommentsController new] animated:YES];

    }else if (indexPath.section == 0 && indexPath.row == 4){
        
        [self.navigationController pushViewController:[MyCollectionController new] animated:YES];

    }
    else if (indexPath.section == 1 && indexPath.row == 0) {
        [self.navigationController pushViewController:[MeSettingController new] animated:YES];
    }else if (indexPath.section == 1 && indexPath.row == 1){
        
        [self.navigationController pushViewController:[QrCodeCardController new] animated:YES];
    }
    else if (indexPath.section == 1 && indexPath.row == 2){
        [self.navigationController pushViewController:[UserFeedbackController new] animated:YES];
    }
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[MeHomeCell class] forCellReuseIdentifier:NSStringFromClass([MeHomeCell class])];
        _listView.tableFooterView = UIView.new;
        [_listView setSeparatorInset:UIEdgeInsetsMake(0, 53, 0, 0)];
        _listView.tableHeaderView = self.headerView;
        if (@available(iOS 11.0, *)) {
            _listView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _listView.separatorColor = SeparatorColor;
    }
    return _listView;
}
-(MeHomeHeaderView*)headerView{
    if(!_headerView){
        _headerView=[[MeHomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 250)];
    }
    return _headerView;
}
-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource =[NSMutableArray array];
        NSArray * array = @[@[@"我的钱包",@"游览历史",@"我的消息",@"我的评论",@"我的收藏"],@[@"我的设置",@"扫一扫",@"用户反馈"]];
        [_dataSource addObjectsFromArray:array];
    }
    return _dataSource;
}
-(NSMutableArray *)imagesArray{
    if (!_imagesArray) {
        _imagesArray =[NSMutableArray array];

        NSArray * array = @[@[@"我的钱包",@"游览历史",@"我的消息",@"我的评论",@"我的收藏"],@[@"我的设置",@"扫一扫",@"用户反馈"]];
        
        [_imagesArray addObjectsFromArray:array];
    }
    return _imagesArray;
}
@end
